# write by 李大宝!
# in 2019,6,1

from flask import Flask, url_for, Response, jsonify, render_template
from werkzeug.routing import BaseConverter
import time
from datetime import datetime

app = Flask(__name__)


@app.template_filter('time_op')
def time_operate(time_value):
    if isinstance(time_value, datetime):
        endtime = datetime.now()
        if (time_value-endtime).minute < 60:
            return '%s分钟前' % (time_value-endtime).minutes
        if (time_value-endtime).hour < 24:
            return '%s小时前' % (time_value-endtime).hours
        else:
            return '%s天前' % (time_value-endtime).days
    else:
        return "your time's template is not in great!"


@app.route('/')
def hello():
    return 'hello world'


@app.route('/login')
def login():
    return render_template('login.html', create_time=datetime.now())


if __name__ == '__main__':
    app.run(debug=True)
